package pe.com.upc.edu.rtt.rest.client.impl;

import java.io.IOException;
import java.util.List;

import pe.com.upc.edu.rtt.Asiento;
import pe.com.upc.edu.rtt.datalayer.util.Util;
import pe.com.upc.edu.rtt.rest.client.WCFAsientosServiceRestClient;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.liferay.portal.kernel.util.PropsUtil;

public class WCFAsientosServiceRestClientImpl implements WCFAsientosServiceRestClient{

	private static Gson gson = new Gson();
		
	public Asiento nuevoAsiento(Asiento asiento) throws IOException {		
		return null;
	}

	public Asiento getAsiento(int idAsiento)  throws IOException {
		String objetoRest = Util.restUtilGet( PropsUtil.get("ws.server.restful.client.WCFAsientosService")+"/Asientos/"+idAsiento, "GET", "Accept", "application/json");
		Asiento asiento = gson.fromJson(objetoRest, Asiento.class);
		return asiento;
	}
	public Asiento modificar(Asiento asiento)throws IOException  {
		return null;
	}
	
	public List<Asiento> listaAsientios() throws IOException {
		String objetoRest = Util.restUtilGet( PropsUtil.get("ws.server.restful.client.WCFAsientosService")+"/Asientos", "GET", "Accept", "application/json");		
		List<Asiento> asientos = gson.fromJson(objetoRest, new TypeToken<List<Asiento>>(){}.getType());
		return asientos;
	}

	public List<Asiento> getListaAsientoDisponiblePorEvento(int idevento)throws IOException  {	
		String objetoRest = Util.restUtilGet( PropsUtil.get("ws.server.restful.client.json.WCFAsientosService")+"/Asientos/Eventos/Disponibles/"+idevento, "GET", "Accept", "application/json");	
		List<Asiento> asientos = gson.fromJson(objetoRest, new TypeToken<List<Asiento>>(){}.getType());
		return asientos;
	}
	
	public int cantidadDeEntradasCompradasPorClientePorEvneto(int cliente, int idevento) throws IOException {
		String objetoRest = Util.restUtilGet( PropsUtil.get("ws.server.restful.client.WCFEventosService")+"/Eventos/"+idevento+"/Cliente/"+cliente, "GET", "Accept", "application/json");	
		int r = Integer.parseInt(objetoRest);
		return r;
	}

}
